<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/7/23
 * Time: 14:52
 */
namespace app\jujin\controller;

use app\admin\service\SystemCateService;
use app\api\service\MemberService;
use controller\JunjinAdmin;
use think\Db;
use think\view\driver\Think;

class Inquiry extends JunjinAdmin
{
    public $table='inquiry';

    public function index()
    {
        $this->title = '询价管理';
        $get = $this->request->get();
        $db = Db::name($this->table);
        if (isset($get['name']) && $get['name'] !== '') {
            $db->whereLike('name', $get['name']);
        }
        return parent::_list($db->order('id desc'));
    }
    protected function _form_filter(&$data)
    {
        if($this->request->isGet()){
            if($this->request->get('id')){
                $this->title='编辑询价信息';
            }else{
                $this->title='添加询价信息';
            }
            //查询物品分类
            $this->assign('supplierCates',Db::name('my_cate')
                ->where('pid',32)
                ->where('status',1)
                ->field('id,title')
                ->select()
            );
            $this->assign('credit_arr',MemberService::credit_arr());
            $data['quotation_detail']=json_decode($data['quotation_detail'],true);
        }else{
            $data['grab_sheet_end_time']=strtotime($data['grab_sheet_end_time']);
            if(isset($data['qd_image'])){
                foreach ($data['qd_image'] as $k=>$v){
                    $quotation_detail[$k]['image']=$v;
                    $quotation_detail[$k]['number']=$data['qd_number'][$k];
                    $quotation_detail[$k]['images']=$data['qd_images'][$k];
                }
                $data['quotation_detail']=json_encode($quotation_detail);
            }

            isset($data['qd_image'])?$data['goods_type_ids']=implode(',',$data['goods_type_ids']):'';
            isset($data['auth'])?$data['auth']=implode(',',$data['auth']):'';
            isset($data['attr'])?$data['attr']=implode(',',$data['attr']):'';
            isset($data['back_type'])?$data['back_type']=implode(',',$data['back_type']):'';
        }
    }

}